/*
ID: khymill1
PROG: heritage 
LANG: C++
*/
#include <string.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>
using namespace std;

    ifstream fin("heritage.in");
    ofstream fout("heritage.out");
class Node {
public:
    char val;
    struct Node* left, *right;
    Node():left(NULL), right(NULL) {}
    Node(char in): val(in), left(NULL), right(NULL){}
};

Node *recover(const char pre[], const char in[], int len)
{
    if (len == 0) return 0;
    Node *head = new Node(pre[0]);
    if (len == 1) return head;
    int index = 0;
    for (int i = 0; i < len; i++) {
        if (in[i] == pre[0]) {
            index = i;
            break;
        }
    }
    head->left = recover(pre+1, in, index);
    head->right = recover(pre+index+1, in+index+1, len-index-1);
    return head;
}

void postOrder(Node *head)
{
    if (!head)
        return;
        postOrder(head->left);
        postOrder(head->right);
    fout << head->val; 

}

int main()
{
    string inOrder, preOrder;
    fin >> inOrder >> preOrder;
    vector<char> post;
    Node *head = recover(preOrder.c_str(), inOrder.c_str(), inOrder.size()); 
    postOrder(head);
    return 0;
}                                          
